/*
 * Kryptik.java
 * Created on November 17, 2000, 2:25 PM
 *
 * This file is part of the Kryptik project.
 *
 * (c) 2000 -- 2001 by SchlumbergerSema 
 * Written by Petr Sturc (psturc@gemalto.com)
 *
 * $Log: Main.java,v $
 * Revision 1.3  2002/01/15 12:15:02  psturc
 * Version strings marked as final
 *
 * 
 */


package com.gemalto.Kryptik;


import com.gemalto.Kryptik.Algo.*;
import com.gemalto.Kryptik.Gui.*;
import com.gemalto.Kryptik.Util.*;

import java.security.Provider;
import java.security.Security;
import java.util.*;
import javax.swing.*;

public final class Main {

	private static final String version = "2.6";
	private static final String msg     = " Kryptik v."+version+
					" Copyrigth 2000-2007  Gemalto\n"+
					" Written by Petr Sturc (petr.sturc@gemalto.com) and Ondrej Borusik (ondrej.borusik@gemalto.com)"; 
	
	
	private static NewGui g;
	private static AlgoManager algoManager, macAlgoManager;

	public static String getVersion(){
		return version;
	}


	public static AlgoManager getAlgoManager(){
		return algoManager;
	}

	public static AlgoManager getMACAlgoManager(){
		return macAlgoManager;
	}



	public static void main(String args[]){

		System.out.println(msg);

		SplashScreen s = new SplashScreen();

		/* At first let's load configuration file "Kryptik.ini
		 * That will be available later via static function Util.getIni()
		 */
		Util.loadIni("Kryptik.ini");


		/* Prepare Beanshell interpreter */
		s.advance("Loading Beanshell ...");
		Beanshell.init();


       //java.security.Security.addProvider(new cryptix.provider.Cryptix());
       //java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        MacAlgo mac1 = new MacAlgo("ISO9797","ISO","DESISO9797MAC");
        Provider p[] = Security.getProviders();
      for (int i = 0; i < p.length; i++) {
          System.out.println(p[i]);
          for (Enumeration e = p[i].keys(); e.hasMoreElements();)
              System.out.println("\t" + e.nextElement());
      }
        

		/* Create algomanagers and export them into all Beanshell's namespaces */
		algoManager = new AlgoManager("CIPHER");
		Beanshell.setVariable("algoManager", algoManager);

		macAlgoManager = new AlgoManager("SIGNATURE");
		Beanshell.setVariable("macAlgoManager", macAlgoManager);

		/* Setup GUI */
		s.advance("Loading GUI ...");
		g = new NewGui(algoManager, macAlgoManager);	
//		SwingUtilities.invokeLater(new Runnable() {
//		public void run(){

	
		/* Run start file */
		s.advance("Loading algos ...");
		try {
			Beanshell.newInterpreter().source(Util.getIni().getValue("INIT","START_FILE"));
		} catch (Exception e){
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
//	         }
//	         });

		/* Show GUI */
		s.advance("Displaying GUI ...");
		g.show();

		s.dispose(); s=null;

	}

}
